package com.naton.common.utils;

import android.Manifest;
import android.app.Activity;
import android.content.Context;

import com.hjq.permissions.OnPermissionCallback;
import com.hjq.permissions.Permission;
import com.hjq.permissions.XXPermissions;
import com.naton.common.callback.AppPermissionCallBack;

import java.util.List;

/**
 * @time: 2022/1/20
 * @author: lifuling
 * @version: v1.0
 * @file_desc: App权限相关
 */
public class AppPermissionUtils {

    /**
     * 请求相机权限
     */
    public static void requestCameraPermission(Activity context, AppPermissionCallBack appPermissionCallBack) {
        XXPermissions.with(context)
                // 申请单个权限
                .permission(Permission.RECORD_AUDIO)
                // 申请多个权限
                //.permission(Permission.Group.CALENDAR)
                // 申请安装包权限
                //.permission(Permission.REQUEST_INSTALL_PACKAGES)
                // 申请悬浮窗权限
                //.permission(Permission.SYSTEM_ALERT_WINDOW)
                // 申请通知栏权限
                //.permission(Permission.NOTIFICATION_SERVICE)
                // 申请系统设置权限
                //.permission(Permission.WRITE_SETTINGS)
                // 设置权限请求拦截器
                //.interceptor(new PermissionInterceptor())
                // 设置不触发错误检测机制
                //.unchecked()
                .request(new OnPermissionCallback() {

                    @Override
                    public void onGranted(List<String> permissions, boolean all) {
                        appPermissionCallBack.onGranted(permissions, all);
                    }

                    @Override
                    public void onDenied(List<String> permissions, boolean never) {
                        // 如果是被永久拒绝就跳转到应用权限系统设置页面
//                        XXPermissions.startPermissionActivity(context, permissions);
                        appPermissionCallBack.onDenied(permissions, never);
                    }
                });

    }
}
